
import os


Base_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))      # ? 不认识



def get_db_uri(dbinfo):
    
    engine = dbinfo.get("ENGINE") or "mysql"
    driver = dbinfo.get("DRIVER") or "pymysql"
    user = dbinfo.get("USER") or""
    password = dbinfo.get("PASSWORD") or""
    host = dbinfo.get("HOST") or""
    port = dbinfo.get("PORT") or""
    name = dbinfo.get("NAME") or""
    
    return "{}+{}://{}:{}@{}:{}/{}".format(engine,driver,user,password,host,port,name)







class Config:                        # 通用
    DEBUG = False
    TESTING = False
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    MAIL_SERVER ="smtp.163.com"
    MAIL_PORT = 25
    MAIL_USERNAME ="yjccheer@163.com"
    MAIL_PASSWORD ="KMUTUTRUFPTKYVRR"
    MAIL_DEFAULT_SENDER =MAIL_USERNAME


    
    
class DevelopConfig(Config):                # 开发环境
    DEBUG = True
    dbinfo = {
        "ENGINE":"mysql",
        "DRIVER":"pymysql",
        "USER":"root",
        "PASSWORD":"123456",
        "HOST":"localhost",
        "PORT":"3306",
        "NAME":"test"
    }
    # MAIL_SERVER ="smtp.163.com"
    # MAIL_PORT = 25
    # MAIL_USERNAME ="yjccheer@163.com"
    # MAIL_PASSWORD ="KMUTUTRUFPTKYVRR"
    # MAIL_DEFAULT_SENDER =MAIL_USERNAME

    SQLALCHEMY_DATABASE_URI = get_db_uri(dbinfo)
    HOST='0.0.0.0',
    PROT=5000


    
    
    
class TestConfig(Config):              #测试环境
    TESTING = True
    dbinfo = {
        "ENGINE":"mysql",
        "DRIVER":"pymysql",
        "USER":"root",
        "PASSWORD":"123456",
        "HOST":"localhost",
        "PORT":"3306",
        "NAME":"test"
    }
    SQLALCHEMY_DATABASE_URI_URI = get_db_uri(dbinfo)
    HOST='0.0.0.0',
    PROT=5000
    
    
    
    
    
class StagingConfig(Config):                #演示环境

    dbinfo = {
        "ENGINE":"mysql",
        "DRIVER":"pymysql",
        "USER":"root",
        "PASSWORD":"123456",
        "HOST":"localhost",
        "PORT":"3306",
        "NAME":"test"
    }
    SQLALCHEMY_DATABASE_URI_URI = get_db_uri(dbinfo)
    
    
    
    
    
class ProductConfig(Config):             #生产环境

    dbinfo = {
        "ENGINE":"mysql",
        "DRIVER":"pymysql",
        "USER":"root",
        "PASSWORD":"123456",
        "HOST":"localhost",
        "PORT":"3306",
        "NAME":"test"
    }
    SQLALCHEMY_DATABASE_URI_URI = get_db_uri(dbinfo)
    
    


envs = {
    "develop":DevelopConfig,
    "testing": TestConfig,
    "staging":StagingConfig,
    "product":ProductConfig,
    "default":DevelopConfig          # 如果忘了指定，默认如此
}